#include <stdio.h>
#include <stdlib.h>

typedef struct tree
{
    int data;
    struct tree *ltree;
    struct tree *rtree;
}tree;

typedef struct queue
{
    tree *data[10];
    int front;
    int rear;
}queue;
typedef struct stack
{
    tree *data[20];
    int index;
}stack;
stack *initstack(){
    stack *s=malloc(sizeof(stack));
    s->index=-1;
    return s;
}
int isemptstack(stack s){
    int flage=0;
    if(s.index==-1) flage=1;
    return flage;
}
int isfullstack(stack s){
    int flage=0;
    if(s.index==19) flage=1;
    return flage;    
}
void pushstack(stack *s,tree *data){
    if(isfullstack(*s)==1){
        printf("这个已经满了");
    }
    else{
        s->data[++s->index]=data;
    }
}
tree *popstack(stack *s){
    tree *data;
    if (isfullstack(*s)==1)
    {
        data=NULL;
    }
    else{
        data=s->data[s->index--];
    }
    return data;
}
queue *initqueue(){
    queue *q=malloc(sizeof(queue));
    q->front=0;
    q->rear=0;
    return q;
}
int isemptqueue(queue q){
    int flage=0;
    if(q.front==q.rear){
        flage=1;
    }
    return flage;
}
int isfullqueue(queue q){
    int flage=0;
    if((q.front+1)%10==q.rear){
        flage==1;
    }
    return flage;
}
void pushqueue(queue *q,tree *data){
    if(isfullqueue(*q)==1){
        printf("满了\n");
    }
    
    else{
        q->data[q->front]=data;
        q->front=(q->front+1)%10;
    }
}
tree *popqueue(queue *q){
    tree *back;
    if(isemptqueue(*q)==1){
        back=0;
    }
    else{
        back=q->data[q->rear];
        q->rear=(q->rear+1)%10;
    }
    return back;
}
